package cn.yunyichina.provider.merchant.pool;

import cn.yunyichina.utils.log.Log;
import cn.yunyichina.utils.log.constant.LogScene;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * Created by kevin on 2017/12/7.
 * @author zhangkewen
 */
public class WorkerThreadPool {
    private static ExecutorService executor;

    static {
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                .setNameFormat("get-message-pool-%d").build();
        executor  = new ThreadPoolExecutor(50, 100, 20, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(5),namedThreadFactory,new ThreadPoolExecutor.AbortPolicy());
    }

    public static  void execute(Runnable task) {
        if (executor == null) {
            Log.e(LogScene.MERCHANT,"获取线程池对象失败");
            return;
        }
        executor.execute(task);
    }
}
